#!/usr/bin/env sh
# Create the  lmdb inputs
# N.B. set the path to the  train + val data dirs
set -e


TOOLS=build/tools
EXAMPLE=examples/classify
DATA_ROOT=/mnt/d/datasets/Scenes_split

TRAIN_DATA_ROOT=$DATA_ROOT/train
if [ ! -d "$TRAIN_DATA_ROOT" ]; then
  echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT"
  echo "Set the TRAIN_DATA_ROOT variable in create_classify.sh to the path where the training data is stored."
  exit 1
fi

VAL_DATA_ROOT=$DATA_ROOT/val
if [ ! -d "$VAL_DATA_ROOT" ]; then
  echo "Error: VAL_DATA_ROOT is not a path to a directory: $VAL_DATA_ROOT"
  echo "Set the VAL_DATA_ROOT variable in create_.sh to the pathn where the validation data is stored."
  exit 1
fi


# Set RESIZE=true to resize the images to 256x256. Leave as false if images have already been resized using another tool.
RESIZE=true
if $RESIZE; then
  RESIZE_HEIGHT=256
  RESIZE_WIDTH=256
else
  RESIZE_HEIGHT=0
  RESIZE_WIDTH=0
fi


echo "Creating train lmdb..."
TRAIN_LMDB_ROOT=/mnt/d/datasets/Scenes_split/Scenes_train_lmdb
if [ -d "$TRAIN_LMDB_ROOT" ]; then
  rm -rf $TRAIN_LMDB_ROOT
fi

GLOG_logtostderr=1 $TOOLS/convert_imageset \
    --resize_height=$RESIZE_HEIGHT \
    --resize_width=$RESIZE_WIDTH \
    --shuffle=true \
    $DATA_ROOT/ \
    $DATA_ROOT/train.txt \
    $TRAIN_LMDB_ROOT


echo "Creating val lmdb..."
VAL_LMDB_ROOT=/mnt/d/datasets/Scenes_split/Scenes_val_lmdb
if [ -d "$VAL_LMDB_ROOT" ]; then
  rm -rf $VAL_LMDB_ROOT
fi

GLOG_logtostderr=1 $TOOLS/convert_imageset \
    --resize_height=$RESIZE_HEIGHT \
    --resize_width=$RESIZE_WIDTH \
    --shuffle=false \
    $DATA_ROOT/ \
    $DATA_ROOT/val.txt \
    $VAL_LMDB_ROOT

echo "Done."
